// MessageMapper.java
package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.MessagePageQueryDTO;
import com.sky.entity.Message;
import com.sky.vo.MessageVO;
import org.apache.ibatis.annotations.*;

@Mapper
public interface MessageMapper {
    @Insert("INSERT INTO message (user_id, content, create_time) " +
            "VALUES (#{userId}, #{content}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Message message);

    @Update("UPDATE message SET reply=#{reply}, reply_time=#{replyTime}, status=2 WHERE id=#{id}")
    void updateReply(Message message);

    @Select("SELECT m.*, u.name FROM message m LEFT JOIN user u ON m.user_id = u.id WHERE m.id=#{id}")
    MessageVO getById(Long id);

    Page<MessageVO> pageQuery(MessagePageQueryDTO dto);
}